<?php
/**
 * @author Radovan Dvorsky
 * @version 20100227
 */
require_once ('library/My/Form/AjaxForm.php');

class Form_Block_AddSubject extends My_Form_AjaxForm {
	
	private $_subjects;
	
	public function init(){
		
		$cache = Zend_Registry::get('cache');
		$cacheName = My_Support::getCacheName('SubjectController','fetchAll');
		
		if(!($this->_subjects = $cache->load($cacheName))){
			$subjectMapper = new Db_Mapper_Subject();
			$this->_subjects = $subjectMapper->fetchAll();
			$cache->save($this->_subjects,$cacheName,array(get_class($subjectMapper)));
		}
		
	}
	
	function __construct($url, $update, $format = 'html', $options = null) {
		parent::__construct($options);
		
		$this->setMethod('post');
		
		$this->setJqueryParams(array(
				'url' => $url,
				'update' => $update,
				'format' => $format,
				'append' => true
			)			
		);
		
		$subjects = new Zend_Form_Element_Select('sid');
		$subjects->setDecorators(array('ViewHelper'));
		
		foreach($this->_subjects as $subject){
			$subjects->addMultiOption($subject->sid,$subject->name);
		}
		
		$block = new Zend_Form_Element_Hidden('Id_oboru');
		$block->setDecorators(array('ViewHelper'));
		
		$submit = new Zend_Form_Element_Button('submitSubject');
		$submit->setLabel('Pridať')
		->setDecorators(array('ViewHelper'));
		
		$this->addAjaxableElements(array($subjects,$block));
		$this->setSender($submit,'onclick');
		
		$this->addElements(array($subjects,$block,$submit));		
	}
}

?>